<template>
  <el-dialog title="编辑审批情况" :visible.sync="dialogVisible" width="80%" :before-close="handleClose">
    <el-form :model="dataForm" :rules="rules" label-position="top" ref="ruleForm">
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item label="权属单位:" prop="ownershipUnit">
            <el-input v-model.trim="dataForm.ownershipUnit" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="鉴定情况:" prop="identify">
            <el-input v-model.trim="dataForm.identify"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="风险等级:" prop="riskLevel">
            <el-input v-model.trim="dataForm.riskLevel"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="风险管控等级:" prop="riskControlLevel">
            <el-input v-model.trim="dataForm.riskControlLevel"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="风险管控措施:" prop="riskControlMeasures">
            <el-input v-model.trim="dataForm.riskControlMeasures"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="施工单位:" prop="constructionUnit">
            <el-input v-model.trim="dataForm.constructionUnit"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="项目经理:" prop="projectManager">
            <el-input v-model.trim="dataForm.projectManager"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="项目经理联系方式:" prop="projectPhone">
            <el-input v-model.trim="dataForm.projectPhone"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="监理单位名称:" prop="supervisionUnit">
            <el-input v-model.trim="dataForm.supervisionUnit"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="监理单位项目总监:" prop="directorName">
            <el-input v-model.trim="dataForm.directorName"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="监理单位项目总监联系方式:" prop="directorPhone">
            <el-input v-model.trim="dataForm.directorPhone"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="预计穿越开始时间:" prop="throughStartTime">
            <el-date-picker
              v-model="dataForm.throughStartTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择日期"
              style="width: 100%"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="预计穿越结束时间:" prop="throughEndTime">
            <el-date-picker
              v-model="dataForm.throughEndTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择日期"
              style="width: 100%"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="应急预案状态:" prop="emergencyPlatType">
            <el-select v-model="dataForm.emergencyPlatType" style="width:100%;" clearable>
              <el-option v-for="item in emergencyPlatTypeList" :key="item.id" :label="item.name" :value="item.id"> </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8" v-if="dataForm.emergencyPlatType !== 2">
          <el-form-item :label="dataForm.emergencyPlatType===0 ? '应急预案完成时间:' : '预计完成时间:'" prop="emergencyPlatTime">
            <el-date-picker
              v-model="dataForm.emergencyPlatTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择日期"
              style="width: 100%"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8" v-if="dataForm.emergencyPlatType !== 0">
          <el-form-item :label="dataForm.emergencyPlatType === 2 ? '不需要的原因:':'应急预案未制定的原因:'" prop="emergencyPlatReason">
            <el-input v-model.trim="dataForm.emergencyPlatReason"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="安全评估和专家评审状态 :" prop="safetyType">
            <el-select v-model="dataForm.safetyType" style="width:100%;" clearable>
              <el-option v-for="item in emergencyPlatTypeList" :key="item.id" :label="item.name" :value="item.id"> </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8" v-if="dataForm.safetyType !== 2">
          <el-form-item :label="dataForm.safetyType===0 ? '安全评估和专家评审完成时间:' : '预计完成时间:'" prop="safetyTime">
            <el-date-picker
              v-model="dataForm.safetyTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择日期"
              style="width: 100%"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8" v-if="dataForm.safetyType !== 0">
          <el-form-item :label="dataForm.safetyType === 2 ? '不需要的原因:' : '安全评估和专家评审未制定的原因:'" prop="safetyReason">
            <el-input v-model.trim="dataForm.safetyReason"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="施工作业安全保护协议状态 :" prop="protocolType">
            <el-select v-model="dataForm.protocolType" style="width:100%;" clearable>
              <el-option v-for="item in protocolTypeList" :key="item.id" :label="item.name" :value="item.id"> </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8" v-if="dataForm.protocolType !== 2">
          <el-form-item :label="dataForm.protocolType===0 ? '施工作业安全保护协议完成时间:' : '预计完成时间:'" prop="protocolTime">
            <el-date-picker
              v-model="dataForm.protocolTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择日期"
              style="width: 100%"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8" v-if="dataForm.protocolType !== 0">
          <el-form-item :label="dataForm.protocolType === 2 ? '不需要的原因:' : '签订施工作业安全保护协议状态未签订的原因:'" prop="protocolReason">
            <el-input v-model.trim="dataForm.protocolReason"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="handleClose">关 闭</el-button>
      <el-button type="primary" @click="submitHandle">确 认</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { updApprovalInfo } from '@/api/constructionScheme'
export default {
  name: 'ApprovalStatus',
  data () {
    return {
      dialogVisible: false,
      dataForm: {
        id: undefined,
        identify: undefined,
        riskLevel: undefined,
        riskControlLevel: undefined,
        riskControlMeasures: undefined,
        constructionUnit: undefined,
        projectManager: undefined,
        projectPhone: undefined,
        supervisionUnit: undefined,
        directorName: undefined,
        directorPhone: undefined,
        throughStartTime: undefined,
        throughEndTime: undefined,
        emergencyPlatType: 0,
        emergencyPlatTime: undefined,
        emergencyPlatReason: undefined,
        safetyType: 0,
        safetyTime: undefined,
        safetyReason: undefined,
        protocolType: 0,
        protocolTime: undefined,
        protocolReason: undefined
      },
      rules: {
        identify: [{ max: 50, message: '最大50个字符', trigger: 'change' }],
        riskLevel: [{ max: 50, message: '最大50个字符', trigger: 'change' }],
        riskControlLevel: [{ max: 50, message: '最大50个字符', trigger: 'change' }],
        riskControlMeasures: [{ max: 50, message: '最大50个字符', trigger: 'change' }],
        constructionUnit: [{ max: 50, message: '最大50个字符', trigger: 'change' }],
        projectManager: [{ max: 50, message: '最大50个字符', trigger: 'change' }],
        projectPhone: [{ max: 50, message: '最大50个字符', trigger: 'change' }],
        supervisionUnit: [{ max: 50, message: '最大50个字符', trigger: 'change' }],
        directorName: [{ max: 50, message: '最大50个字符', trigger: 'change' }],
        directorPhone: [{ max: 50, message: '最大50个字符', trigger: 'change' }],
        emergencyPlatReason: [{ max: 50, message: '最大50个字符', trigger: 'change' }],
        safetyReason: [{ max: 50, message: '最大50个字符', trigger: 'change' }],
        protocolReason: [{ max: 50, message: '最大50个字符', trigger: 'change' }]
      },
      emergencyPlatTypeList: [
        {
          id: 0,
          name: '已制定'
        },
        {
          id: 1,
          name: '未制定'
        },
        {
          id: 2,
          name: '不需要'
        }
      ],
      protocolTypeList: [
        {
          id: 0,
          name: '已签订'
        },
        {
          id: 1,
          name: '未签订'
        },
        {
          id: 2,
          name: '不需要'
        }
      ]
    }
  },
  methods: {
    init (row) {
      this.dataForm.id = row.schemeId
      this.dataForm.ownershipUnit = row.ownershipUnit
      this.dataForm.identify = row.identify
      this.dataForm.riskLevel = row.riskLevel
      this.dataForm.riskControlLevel = row.riskControlLevel
      this.dataForm.riskControlMeasures = row.riskControlMeasures
      this.dataForm.constructionUnit = row.constructionUnit
      this.dataForm.projectManager = row.projectManager
      this.dataForm.projectPhone = row.projectPhone
      this.dataForm.supervisionUnit = row.supervisionUnit
      this.dataForm.directorName = row.directorName
      this.dataForm.directorPhone = row.directorPhone
      this.dataForm.throughStartTime = row.throughStartTime
      this.dataForm.throughEndTime = row.throughEndTime
      this.dataForm.emergencyPlatType = row.emergencyPlatType
      this.dataForm.emergencyPlatTime = row.emergencyPlatTime
      this.dataForm.emergencyPlatReason = row.emergencyPlatReason
      this.dataForm.safetyType = row.safetyType
      this.dataForm.safetyTime = row.safetyTime
      this.dataForm.safetyReason = row.safetyReason
      this.dataForm.protocolType = row.protocolType
      this.dataForm.protocolTime = row.protocolTime
      this.dataForm.protocolReason = row.protocolReason
      this.dialogVisible = true
    },
    submitHandle () {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          updApprovalInfo(this.dataForm).then((res) => {
            if (res.code === 'success') {
              this.$message.success('操作成功')
              this.$emit('goBack')
              this.$refs.ruleForm.resetFields()
              this.dialogVisible = false
            } else {
              this.$message.error(res.msg)
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    handleClose () {
      this.$refs.ruleForm.resetFields()
      this.dialogVisible = false
    }
  }
}
</script>
<style scoped lang="scss"></style>
